home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / LL_LAND.ZIP / LL_PAL.INC < prev    next >
Text File  |  1993-05-11  |  12KB  |  541 lines

  1. ;; *************************************************************************
  2. ;; LL_PAL.INC   -  Lord Logic's Palette Manipulation Routines  -  LL_PAL.INC
  3. ;;          - PRIMOR ViDeO GFX Engine v1.2 * Copyright (C) 1992-93 -
  4. ;;
  5. ;; No docs or nfo written for these routines yet.  Given with LL_LAND as a
  6. ;; programming example.  Focus of the example is the 3D Landscape, and not
  7. ;; these routines.  They are pretty straight forward and easy to figure out.
  8. ;;
  9. ;; *************************************************************************
  10. ;; Routines:
  11. ;; ll_palcycle(char far *, uchar, uint, char);
  12. ;; ll_palcol(char far *, uchar, uint, char, char, char);
  13. ;; ll_palput(char far *);
  14. ;; ll_palget(char far *);
  15. ;; ll_palfade(char far *);
  16. ;; ll_palramp(char far *, uchar, uint, char, char, char, char, char, char);
  17. ;; ll_palupdate();
  18. ;; *
  19. ;; NOTE: None of the above routines alter the actual VGA Palette EXCEPT for
  20. ;;       ll_palupdate().  They alter the passed buffer.  To change the
  21. ;;       actual palette, call one of the above followed by either:
  22. ;;       ll_palput() -OR- a call to ll_palfade() followed by ll_palupdate().
  23. ;; *
  24. .data
  25. MM     equ     6
  26.     LL_PAL  db      768 dup (?)
  27.  
  28. .code
  29. ll_palramp      proc
  30.     push    bp
  31.     mov     bp,sp
  32.     push    ds
  33.     push    es
  34.     push    di
  35.     push    si
  36.  
  37.     mov     ax,@data
  38.     mov     ds,ax
  39.  
  40.     mov     ax,1
  41.     stc
  42. ;; *
  43. ;; Get passed parameters . . .
  44. ;; *
  45.     mov     di,[bp+MM+2]    ;; Set ES:[DI] to point to starting
  46.     mov     es,di           ;; : of buffer to change  . . .
  47.     mov     di,[bp+MM]      ;; :
  48.     mov     ax,[bp+MM+4]    ;; :
  49.     mov     bx,3
  50.     mul     bx
  51.     add     di,ax
  52.     mov     cx,[bp+MM+6]    ;; Length of ramp
  53.     or      cx,cx           ;; Check length
  54.     jz      llpr_e          ;; : If 0, exit NOW!
  55.     add     cx,[bp+MM+4]    ;; : And if ramp range < 256 . . .
  56.     cmp     cx,256          ;; :
  57.     ja      llpr_e          ;; :
  58.     mov     cx,[bp+MM+6]    ;; :
  59.  
  60. ;; *
  61. ;; Compute the RED RAMP
  62. ;; *
  63.     push    di
  64.     push    cx
  65.     mov     bl,[bp+MM+8]    ;; Red 1
  66.     mov     bh,[bp+MM+14]   ;; Red 2
  67.     mov     si,bx           ;; Set SI to hold the starting point
  68.     cmp     bh,bl           ;; Check if there is a change
  69.     jne     llpr_1          ;; : and if so, then figure out ratio
  70.     xor     ax,ax           ;; : otherwise, set it to 0.
  71.     jmp     llpr_3          ;; :
  72.  
  73. llpr_1: xchg    bl,bh           ;; Set AX to hold the ratio
  74.     sub     bl,bh           ;; :
  75.     xor     bh,bh           ;; :
  76.     test    bl,10000000b    ;; Check if BL is negative
  77.     jz      llpr_2          ;; : If not, continue, else
  78.     or      bh,11111111b    ;; : Set BH accordingly . . .
  79. llpr_2: mov     ax,0100h        ;; Ratio = (256*dy)/dx
  80.     imul    bx              ;; :
  81.     idiv    cx              ;; :
  82.  
  83. llpr_3: mov     bx,si
  84.     mov     bh,al
  85. llpr_4: mov     es:[di],bl
  86.     add     bh,al
  87.     adc     bl,ah
  88.     add     di,3
  89.     loop    llpr_4
  90.  
  91.     pop     cx
  92.     pop     di
  93.  
  94. ;; *
  95. ;; Compute the GREEN RAMP
  96. ;; *
  97.     push    di
  98.     push    cx
  99.     mov     bl,[bp+MM+10]   ;; Green 1
  100.     mov     bh,[bp+MM+16]   ;; Green 2
  101.     mov     si,bx           ;; Set SI to hold the starting point
  102.     cmp     bh,bl           ;; Check if there is a change
  103.     jne     llpr_5          ;; : and if so, then figure out ratio
  104.     xor     ax,ax           ;; : otherwise, set it to 0.
  105.     jmp     llpr_7          ;; :
  106.  
  107. llpr_5: xchg    bl,bh           ;; Set AX to hold the ratio
  108.     sub     bl,bh           ;; :
  109.     xor     bh,bh           ;; :
  110.     test    bl,10000000b    ;; Check if BL is negative
  111.     jz      llpr_6          ;; : If not, continue, else
  112.     or      bh,11111111b    ;; : Set BH accordingly . . .
  113. llpr_6: mov     ax,0100h        ;; Ratio = (256*dy)/dx
  114.     imul    bx              ;; :
  115.     idiv    cx              ;; :
  116.  
  117. llpr_7: mov     bx,si
  118.     inc     di
  119. llpr_8: mov     es:[di],bl
  120.     add     bh,al
  121.     adc     bl,ah
  122.     add     di,3
  123.     loop    llpr_8
  124.  
  125.     pop     cx
  126.     pop     di
  127.  
  128. ;; *
  129. ;; Compute the BLUE RAMP
  130. ;; *
  131.     push    di
  132.     push    cx
  133.     mov     bl,[bp+MM+12]   ;; Blue 1
  134.     mov     bh,[bp+MM+18]   ;; Blue 2
  135.     mov     si,bx           ;; Set SI to hold the starting point
  136.     cmp     bh,bl           ;; Check if there is a change
  137.     jne     llpr_9          ;; : and if so, then figure out ratio
  138.     xor     ax,ax           ;; : otherwise, set it to 0.
  139.     jmp     llpr_11         ;; :
  140.  
  141. llpr_9: xchg    bl,bh           ;; Set AX to hold the ratio
  142.     sub     bl,bh           ;; :
  143.     xor     bh,bh           ;; :
  144.     test    bl,10000000b    ;; Check if BL is negative
  145.     jz      llpr_10         ;; : If not, continue, else
  146.     or      bh,11111111b    ;; : Set BH accordingly . . .
  147. llpr_10:mov     ax,0100h        ;; Ratio = (256*dy)/dx
  148.     imul    bx              ;; :
  149.     idiv    cx              ;; :
  150.  
  151. llpr_11:mov     bx,si
  152.     add     di,2
  153. llpr_12:mov     es:[di],bl
  154.     add     bh,al
  155.     adc     bl,ah
  156.     add     di,3
  157.     loop    llpr_12
  158.  
  159.     pop     cx
  160.     pop     di
  161.  
  162.     xor     ax,ax
  163.     clc
  164.  
  165. llpr_e: pop     si
  166.     pop     di
  167.     pop     es
  168.     pop     ds
  169.     pop     bp
  170.     ret
  171. ll_palramp      endp
  172.  
  173.  
  174. ;;
  175. ;; NOTE:  Need to add a horizontal retrace check every 3 bytes output to the
  176. ;;        pal port to remove slight flicker from some video displays.
  177. ;;
  178. ll_palfade      proc
  179.     push    bp
  180.     mov     bp,sp
  181.     push    ds
  182.     push    es
  183.     push    di
  184.     push    si
  185.  
  186.     mov     ax,@data
  187.     mov     ds,ax
  188.  
  189.     mov     di,@data
  190.     mov     es,di
  191.     mov     di,offset LL_PAL
  192.  
  193.     mov     si,[bp+MM+2]
  194.     mov     ds,si
  195.     mov     si,[bp+MM]
  196.     add     si,768
  197.  
  198. llfp_1: xor     ah,ah
  199.     xor     di,di
  200.     sub     si,768
  201.     mov     cx,768
  202. llfp_2: mov     al,es:[di]      ;
  203.     cmp     al,[si]         ;
  204.     je      llfp_5          ;
  205.     ja      llfp_4
  206. llfp_3: add     al,2
  207. llfp_4: dec     al
  208.     mov     ah,1
  209.     mov     es:[di],al      ;
  210. llfp_5: inc     si
  211.     inc     di
  212.     loop    llfp_2
  213.     mov     dx,ax           ; Store return code
  214.     jmp     llfp_6          ; step ONLY ONCE through!
  215.     ;or      ah,ah           ;
  216.     ;jz      llfp_6          ;
  217.     ;push    ax
  218.     ;call    ll_palupdate
  219.     ;pop     ax
  220.     jmp     llfp_1
  221.  
  222. llfp_6: mov     ax,@data
  223.     mov     ds,ax
  224.  
  225.     xchg    dx,ax
  226.     mov     al,ah
  227.     clc
  228.  
  229. llfp_e: pop     si
  230.     pop     di
  231.     pop     es
  232.     pop     ds
  233.     pop     bp
  234.     ret
  235. ll_palfade      endp
  236.  
  237. ;; ************************************************************************
  238. ;; char ll_palcycle(char far *buf, unsigned char start, unsigned char size, char dir);
  239. ;; USE :  Send 1 in DIR for forward, 1 in DIR for backward cycle.
  240. ;; ************************************************************************
  241. ll_palcycle        proc
  242.     push    bp
  243.     mov     bp,sp
  244.     push    ds
  245.     push    es
  246.     push    di
  247.     push    si
  248.  
  249.     mov     ax,@DATA
  250.     mov     ds,ax
  251.  
  252. ;; *
  253. ;; Check the passed parameters . . .
  254. ;; *
  255.     mov     ax,[bp+MM+4]
  256.     add     ax,[bp+MM+6]
  257.     cmp     ax,256
  258.     ja      llc_exit
  259.     or      ax,ax
  260.     jz      llc_exit
  261.  
  262. ;; *
  263. ;; Slide the PALETTE section ONE position . . .
  264. ;; *
  265.     mov     ax,[bp+MM+2]            ;; PAL Segment
  266.     mov     es,ax
  267.     mov     ds,ax
  268.     mov     ax,[bp+MM+4]
  269.     mov     bx,3
  270.     mul     bx
  271.     mov     di,ax
  272.     add     di,[bp+MM]              ;; PAL Offset
  273.     mov     si,ax
  274.     mov     ax,[bp+MM+6]
  275.     mul     bx
  276.  
  277.     cmp     byte ptr [bp+MM+8],1
  278.     jne     llc_b
  279. llc_f:  cld                             ;; Cycle forward . . .
  280.     mov     di,770
  281.     mov     cx,3
  282.     rep     movsb
  283.     mov     di,si
  284.     sub     di,3
  285.     mov     cx,ax
  286.     sub     cx,3
  287.     rep     movsb
  288.     mov     cx,3
  289.     mov     si,770
  290.     rep     movsb
  291.     jmp     llc_1
  292.  
  293. llc_b:  std                             ;; Cycle backward . . .
  294.     mov     cx,3
  295.     add     si,ax
  296.     dec     si
  297.     mov     di,772
  298.     rep     movsb
  299.     mov     di,si
  300.     add     di,3
  301.     mov     cx,ax
  302.     sub     cx,3
  303.     rep     movsb
  304.     mov     cx,3
  305.     mov     si,772
  306.     rep     movsb
  307.  
  308. llc_1:  clc
  309.     xor     ax,ax
  310.  
  311. ;; *
  312. ;; Exit the routine . . .
  313. ;; *
  314. llc_exit:
  315.     cld
  316.     pop     si
  317.     pop     di
  318.     pop     es
  319.     pop     ds
  320.     pop     bp
  321.     ret
  322. ll_palcycle        endp
  323.  
  324. ll_palcol       proc
  325.     push    bp
  326.     mov     bp,sp
  327.     push    ds
  328.     push    es
  329.     push    di
  330.  
  331.     mov     ax,@data
  332.     mov     ds,ax
  333.  
  334.  
  335. ;; *
  336. ;; Check the passed parameters . . .
  337. ;; *
  338.     mov     ax,[bp+MM+4]
  339.     add     ax,[bp+MM+6]
  340.     cmp     ax,256
  341.     ja      llpc_e
  342.     or      ax,ax
  343.     jz      llpc_e
  344.  
  345. ;; *
  346. ;; Set PAL to new settings . . .
  347. ;; *
  348.     mov     bx,3
  349.     mov     ax,[bp+MM+4]
  350.     mul     bx
  351.     mov     di,ax
  352.     add     di,[bp+MM]              ;; PAL Offset
  353.     mov     es,[bp+MM+2]            ;; PAL Segment
  354.     mov     cx,[bp+MM+6]
  355.     mov     ah,[bp+MM+8]
  356.     mov     bh,[bp+MM+10]
  357.     mov     bl,[bp+MM+12]
  358. llpc_l: mov     es:[di],ah
  359.     mov     es:[di+1],bh
  360.     mov     es:[di+2],bl
  361.     add     di,3
  362.     loop    llpc_l
  363.  
  364.     xor     ax,ax
  365.     clc
  366.  
  367. llpc_e: pop     di
  368.     pop     es
  369.     pop     ds
  370.     pop     bp
  371.     ret
  372. ll_palcol       endp
  373.  
  374. ;; ************************************************************************
  375. ;; char ll_palget(char far *buf);
  376. ;; Purpose:  This routine gets the displays palette sets LL_PAL to it and
  377. ;;           also sets buf to the same settings.
  378. ;; ************************************************************************
  379. ll_palget       proc
  380.     push    bp
  381.     mov     bp,sp
  382.     push    ds
  383.     push    es
  384.     push    di
  385.     push    si
  386.  
  387.     mov     ax,@data
  388.     mov     ds,ax
  389.  
  390.     mov     di,@data
  391.     mov     es,di
  392.     mov     di,offset LL_PAL
  393.     mov     cx,768
  394.     mov     dx,03c7h
  395.     xor     al,al
  396.     out     dx,al
  397.     add     dx,2
  398. llpg_1: in      al,dx
  399.     mov     es:[di],al
  400.     inc     di
  401.     loop    llpg_1
  402.  
  403.     mov     es,[bp+MM+2]
  404.     mov     di,[bp+MM]
  405.     mov     si,@data
  406.     mov     ds,si
  407.     mov     si,offset LL_PAL
  408.     mov     cx,768
  409.     rep     movsb
  410.  
  411.     xor     ax,ax
  412.     clc
  413.  
  414. llpg_e: pop     si
  415.     pop     di
  416.     pop     es
  417.     pop     ds
  418.     ret
  419. ll_palget       endp
  420.  
  421.  
  422. ;; ************************************************************************
  423. ;; char ll_palput(char far *buf);
  424. ;; Purpose:  This routine sets LL_PAL to the contents of buf and also sets
  425. ;;           the displays palette to the new LL_PAL.
  426. ;; ************************************************************************
  427. ll_palput       proc
  428.     push    bp
  429.     mov     bp,sp
  430.     push    ds
  431.     push    es
  432.     push    si
  433.     push    di
  434.  
  435.     mov     ax,@data
  436.     mov     ds,ax
  437.  
  438.     mov     di,@data
  439.     mov     es,di
  440.     mov     di,offset LL_PAL
  441.  
  442.     mov     si,[bp+MM+2]
  443.     mov     ds,si
  444.     mov     si,[bp+MM]
  445.  
  446. ;; *
  447. ;; Fill LL_PAL with new values . . .
  448. ;; *
  449.     cld
  450.     mov     cx,768
  451.     rep     movsb
  452.  
  453. ;; *
  454. ;; Wait for VERTICAL RETRACE . . .
  455. ;; *
  456. llpp_v: mov     dx,03dah                ;; vertical retrace port
  457. llpp_1: in      al,dx                   ;; read port
  458.     and     al,08h                  ;; mask out bits
  459.     jnz     llpp_1                  ;; if not clear, go back
  460. llpp_2: in      al,dx                   ;; read port
  461.     and     al,08h                  ;; mask out bits
  462.     jz      llpp_2                  ;; if clear, go back
  463.  
  464. ;; *
  465. ;; Fill Palette . . .
  466. ;; *
  467.     mov     dx,03c8h
  468.     xor     al,al
  469.     out     dx,al
  470.     inc     dx
  471.     mov     cx,768
  472.     sub     si,768
  473. llpp_3: mov     al,[si]
  474.     out     dx,al
  475.     inc     si
  476.     loop    llpp_3
  477.  
  478.     clc
  479.     xor     ax,ax
  480.  
  481. llpp_e: pop     di
  482.     pop     si
  483.     pop     es
  484.     pop     ds
  485.     pop     bp
  486.     ret
  487. ll_palput       endp
  488.  
  489. ll_palupdate    proc
  490.     push    ds
  491.     push    si
  492.  
  493.     mov     ax,@data
  494.     mov     ds,ax
  495.  
  496. ;; *
  497. ;; Wait for VERTICAL RETRACE . . .
  498. ;; *
  499. llpu_v: mov     dx,03dah                ;; vertical retrace port
  500. llpu_1: in      al,dx                   ;; read port
  501.     and     al,08h                  ;; mask out bits
  502.     jnz     llpu_1                  ;; if not clear, go back
  503. llpu_2: in      al,dx                   ;; read port
  504.     and     al,08h                  ;; mask out bits
  505.     jz      llpu_2                  ;; if clear, go back
  506.  
  507. ;; *
  508. ;; Fill Palette . . .
  509. ;; *
  510.     mov     dx,03c8h
  511.     xor     al,al
  512.     out     dx,al
  513.     inc     dx
  514.     mov     cx,768/3
  515.     mov     si,@data
  516.     mov     ds,si
  517.     mov     si,offset LL_PAL
  518. llpu_3:                                 ;; Add a horizontal retrace
  519.                     ;; check here.  I can't find
  520.                     ;; the register port nfo in my
  521.                     ;; book.  oh well.
  522.  
  523.     mov     ax,[si]
  524.     and     ax,0011111100111111b
  525.     out     dx,al
  526.     mov     al,ah
  527.     out     dx,al
  528.     mov     al,[si+2]
  529.     and     al,00111111b
  530.     out     dx,al
  531.     add     si,3
  532.     loop    llpu_3
  533.  
  534.     xor     ax,ax
  535.     clc
  536.  
  537. llpu_e: pop     si
  538.     pop     ds
  539.     ret
  540. ll_palupdate    endp
  541.